/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interfaz.Alumnos;

import static Auxiliares.MensajesCodigosError.ERROR_MATRICULA;
import static Auxiliares.MensajesCodigosError.ERROR_TELEFONO;
import static Auxiliares.MensajesCodigosError.INFO_ALUMNO_INCOMPLETA;
import Controladores.ControladorCamposTexto;
import Controladores.GestorAlumnos;
import Controladores.GestorMensajes;
import Modelo.Alumno;
import java.awt.Color;
import java.awt.event.KeyEvent;

/**
 *
 * @author Marko
 */
public class InterfazAltaAlumno extends javax.swing.JDialog {

    /**
     * Creates new form InterfazAltaAlumno
     * @param _pantallaPadre
     * @param _modal
     */
    public InterfazAltaAlumno(
     java.awt.Frame _pantallaPadre,
     boolean _modal
    ) {
        
        super(_pantallaPadre,"Alta Alumno", _modal);
        initComponents();
        
        establecerFondoYPosicion(_pantallaPadre);
        datosCompletos = false;
        administradorMensajes = new GestorMensajes();
        controladorCampos = new ControladorCamposTexto();
        
    }

    /**
     * crea la pantalla para completar la informacion del alumno
     * @param _pantallaPadre
     * @param _modal
     * @param _matricula 
     */
    public InterfazAltaAlumno(
     java.awt.Frame _pantallaPadre,
     boolean _modal,
     String _matricula
    ) {
        
        super(_pantallaPadre,"Completar informacion del alumno", _modal);
        initComponents();
        
        establecerFondoYPosicion(_pantallaPadre);
        datosCompletos = false;
        administradorMensajes = new GestorMensajes();
        controladorCampos = new ControladorCamposTexto();
        mostrarBotonesActualizacion();
        mostrarInformacion(_matricula);
    }
    
    /** 
     * @return Devuelve verdadero si y solo si los datos del alumno fueron actualizados
     * de forma correcta
     */
    public boolean obtenerConfirmacionCompletado(){
        return datosCompletos;
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonActualizar = new javax.swing.JButton();
        jPanelFondo = new javax.swing.JPanel();
        jPanelAlumno = new javax.swing.JPanel();
        jLabelCorreo = new javax.swing.JLabel();
        jTextFieldCorreo = new javax.swing.JTextField();
        jLabelMatricula = new javax.swing.JLabel();
        jTextFieldMatricula = new javax.swing.JTextField();
        jComboBoxLicenciatura = new javax.swing.JComboBox();
        jLabelLicenciatura = new javax.swing.JLabel();
        jPanelPersona = new javax.swing.JPanel();
        jTextFieldTelefono = new javax.swing.JTextField();
        jLabelNombres = new javax.swing.JLabel();
        jTextFieldNombre = new javax.swing.JTextField();
        jLabelTelefono = new javax.swing.JLabel();
        jLabelDireccion = new javax.swing.JLabel();
        jTextFieldDireccion = new javax.swing.JTextField();
        jPanelBotones = new javax.swing.JPanel();
        jButtonCancelar = new javax.swing.JButton();
        jButtonAceptar = new javax.swing.JButton();
        jLabelMensaje = new javax.swing.JLabel();

        jButtonActualizar.setText("Actualizar");
        jButtonActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonActualizarActionPerformed(evt);
            }
        });
        jButtonActualizar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButtonActualizarKeyPressed(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanelFondo.setOpaque(false);

        jPanelAlumno.setOpaque(false);

        jLabelCorreo.setText("*Correo");

        jTextFieldCorreo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldCorreoFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldCorreoFocusLost(evt);
            }
        });
        jTextFieldCorreo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldCorreoKeyPressed(evt);
            }
        });

        jLabelMatricula.setText("*Matricula");

        jTextFieldMatricula.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldMatriculaFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldMatriculaFocusLost(evt);
            }
        });
        jTextFieldMatricula.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldMatriculaKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldMatriculaKeyTyped(evt);
            }
        });

        jComboBoxLicenciatura.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione una Licenciatura", "Ingeniería en Alimentos", "Ingeniería en Biotecnología", "Ingeniería Industrial Logística", "Ingeniería Química", "Ingeniería Química Industrial", "Química Industrial" }));

        jLabelLicenciatura.setText("*Licenciatura");

        javax.swing.GroupLayout jPanelAlumnoLayout = new javax.swing.GroupLayout(jPanelAlumno);
        jPanelAlumno.setLayout(jPanelAlumnoLayout);
        jPanelAlumnoLayout.setHorizontalGroup(
            jPanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelAlumnoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelAlumnoLayout.createSequentialGroup()
                        .addComponent(jLabelMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(34, 34, 34)
                        .addComponent(jTextFieldMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanelAlumnoLayout.createSequentialGroup()
                        .addGroup(jPanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelAlumnoLayout.createSequentialGroup()
                                .addComponent(jLabelCorreo)
                                .addGap(52, 52, 52)
                                .addComponent(jTextFieldCorreo))
                            .addGroup(jPanelAlumnoLayout.createSequentialGroup()
                                .addComponent(jLabelLicenciatura, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jComboBoxLicenciatura, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addContainerGap())))
        );
        jPanelAlumnoLayout.setVerticalGroup(
            jPanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelAlumnoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldMatricula, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addGroup(jPanelAlumnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelLicenciatura)
                    .addComponent(jComboBoxLicenciatura, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelPersona.setOpaque(false);

        jTextFieldTelefono.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldTelefonoFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldTelefonoFocusLost(evt);
            }
        });
        jTextFieldTelefono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldTelefonoKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldTelefonoKeyTyped(evt);
            }
        });

        jLabelNombres.setText("*Nombre(s)");

        jTextFieldNombre.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldNombreFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldNombreFocusLost(evt);
            }
        });
        jTextFieldNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldNombreKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldNombreKeyTyped(evt);
            }
        });

        jLabelTelefono.setText("Telefono");

        jLabelDireccion.setText("*Direccion");

        jTextFieldDireccion.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldDireccionFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldDireccionFocusLost(evt);
            }
        });
        jTextFieldDireccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldDireccionKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldDireccionKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanelPersonaLayout = new javax.swing.GroupLayout(jPanelPersona);
        jPanelPersona.setLayout(jPanelPersonaLayout);
        jPanelPersonaLayout.setHorizontalGroup(
            jPanelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPersonaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabelTelefono, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabelDireccion, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelNombres, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                    .addComponent(jTextFieldDireccion))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelPersonaLayout.setVerticalGroup(
            jPanelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPersonaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNombres, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabelTelefono, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextFieldTelefono, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelDireccion)
                    .addComponent(jTextFieldDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jPanelBotones.setOpaque(false);

        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });
        jButtonCancelar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButtonCancelarKeyPressed(evt);
            }
        });

        jButtonAceptar.setText("Aceptar");
        jButtonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAceptarActionPerformed(evt);
            }
        });
        jButtonAceptar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButtonAceptarKeyPressed(evt);
            }
        });

        jLabelMensaje.setText("Los campos marcados con un asterisco(*) son obligatorios");

        javax.swing.GroupLayout jPanelBotonesLayout = new javax.swing.GroupLayout(jPanelBotones);
        jPanelBotones.setLayout(jPanelBotonesLayout);
        jPanelBotonesLayout.setHorizontalGroup(
            jPanelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelMensaje)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButtonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelBotonesLayout.setVerticalGroup(
            jPanelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCancelar)
                    .addComponent(jButtonAceptar)
                    .addComponent(jLabelMensaje))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanelFondoLayout = new javax.swing.GroupLayout(jPanelFondo);
        jPanelFondo.setLayout(jPanelFondoLayout);
        jPanelFondoLayout.setHorizontalGroup(
            jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanelBotones, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addComponent(jPanelPersona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanelAlumno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(0, 18, Short.MAX_VALUE))
        );
        jPanelFondoLayout.setVerticalGroup(
            jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanelPersona, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelAlumno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(17, 17, 17)
                .addComponent(jPanelBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelFondo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelFondo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldNombreKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldNombreKeyPressed
        controladorCampos.enterTab(evt);
    }//GEN-LAST:event_jTextFieldNombreKeyPressed

    private void jTextFieldNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldNombreKeyTyped
        if(controladorCampos.formatoAlfabetico(evt)){
            controladorCampos.formatoMayusculas(evt);
        }
    }//GEN-LAST:event_jTextFieldNombreKeyTyped

    private void jTextFieldNombreFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldNombreFocusLost
        controladorCampos.esCampoTextoEnBlanco(jTextFieldNombre);
    }//GEN-LAST:event_jTextFieldNombreFocusLost

    private void jTextFieldNombreFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldNombreFocusGained
        controladorCampos.campoEnUso(jTextFieldNombre);
    }//GEN-LAST:event_jTextFieldNombreFocusGained

    private void jTextFieldTelefonoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldTelefonoKeyPressed
        controladorCampos.enterTab(evt);
    }//GEN-LAST:event_jTextFieldTelefonoKeyPressed

    private void jTextFieldTelefonoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldTelefonoKeyTyped
        controladorCampos.formatoNumerico(evt);
    }//GEN-LAST:event_jTextFieldTelefonoKeyTyped

    private void jTextFieldTelefonoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldTelefonoFocusLost
        if(controladorCampos.esCampoTextoEnBlanco(jTextFieldTelefono)){
            controladorCampos.campoEnUso(jTextFieldTelefono);
        }else{
            int longitudTelLocal = 7;
            int longitudTelCel = 10;
            if(!controladorCampos.verificarLongitud(jTextFieldTelefono, longitudTelLocal)
                    && !controladorCampos.verificarLongitud(jTextFieldTelefono, longitudTelCel)){
                administradorMensajes.mensajeError(ERROR_TELEFONO, jTextFieldTelefono);
            }
        }
    }//GEN-LAST:event_jTextFieldTelefonoFocusLost

    private void jTextFieldTelefonoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldTelefonoFocusGained
        controladorCampos.campoEnUso(jTextFieldTelefono);
    }//GEN-LAST:event_jTextFieldTelefonoFocusGained

    private void jTextFieldDireccionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldDireccionKeyPressed
        controladorCampos.enterTab(evt);
    }//GEN-LAST:event_jTextFieldDireccionKeyPressed

    private void jTextFieldDireccionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldDireccionKeyTyped
        if(controladorCampos.formatoDireccion(evt)){
            controladorCampos.formatoMayusculas(evt);
        }
    }//GEN-LAST:event_jTextFieldDireccionKeyTyped

    private void jTextFieldDireccionFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldDireccionFocusLost
        controladorCampos.esCampoTextoEnBlanco(jTextFieldDireccion);
    }//GEN-LAST:event_jTextFieldDireccionFocusLost

    private void jTextFieldDireccionFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldDireccionFocusGained
        controladorCampos.campoEnUso(jTextFieldDireccion);
    }//GEN-LAST:event_jTextFieldDireccionFocusGained

    private void jTextFieldMatriculaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldMatriculaKeyPressed
        controladorCampos.enterTab(evt);
    }//GEN-LAST:event_jTextFieldMatriculaKeyPressed

    private void jTextFieldMatriculaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldMatriculaKeyTyped
        controladorCampos.formatoNumerico(evt);
    }//GEN-LAST:event_jTextFieldMatriculaKeyTyped

    private void jTextFieldMatriculaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldMatriculaFocusLost
        if(!controladorCampos.esCampoTextoEnBlanco(jTextFieldMatricula)){
            int longitudMatricula = 8;
            if(!controladorCampos.verificarLongitud(jTextFieldMatricula, longitudMatricula)){
                administradorMensajes.mensajeError(ERROR_MATRICULA, jTextFieldMatricula);
            } 
        }
    }//GEN-LAST:event_jTextFieldMatriculaFocusLost

    private void jTextFieldMatriculaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldMatriculaFocusGained
        controladorCampos.campoEnUso(jTextFieldMatricula);
    }//GEN-LAST:event_jTextFieldMatriculaFocusGained

    private void jTextFieldCorreoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCorreoKeyPressed
        controladorCampos.enterTab(evt);
    }//GEN-LAST:event_jTextFieldCorreoKeyPressed

    private void jTextFieldCorreoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldCorreoFocusLost
        controladorCampos.formatoCorreo(jTextFieldCorreo);
    }//GEN-LAST:event_jTextFieldCorreoFocusLost

    private void jTextFieldCorreoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldCorreoFocusGained
        controladorCampos.campoEnUso(jTextFieldCorreo);
    }//GEN-LAST:event_jTextFieldCorreoFocusGained

    private void jButtonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAceptarActionPerformed
        registrarNuevoAlumno();
    }//GEN-LAST:event_jButtonAceptarActionPerformed

    private void jButtonAceptarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButtonAceptarKeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            registrarNuevoAlumno();
        }
    }//GEN-LAST:event_jButtonAceptarKeyPressed

    private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
        cerrar();
    }//GEN-LAST:event_jButtonCancelarActionPerformed

    private void jButtonCancelarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButtonCancelarKeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            cerrar();
        }
    }//GEN-LAST:event_jButtonCancelarKeyPressed

    private void jButtonActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonActualizarActionPerformed
        actualizarInformacion();
    }//GEN-LAST:event_jButtonActualizarActionPerformed

    private void jButtonActualizarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButtonActualizarKeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            actualizarInformacion();
        }
    }//GEN-LAST:event_jButtonActualizarKeyPressed
    
    /**
     * solicita al alumno con la matricula especificada
     * @param _matricula
     * @return Devuelve al alumno encontrado
     */
    private Alumno buscarAlumno(String _matricula){
        GestorAlumnos administradorAlumnos = new GestorAlumnos();
        return administradorAlumnos.buscarAlumno(_matricula);
    }
    
    /**
     * toma los datos del alumno apartir de los campos
     * @return Devuelve al alumno con todos sus campos
     */
    private Alumno construirAlumno(){
        Alumno alumno = new Alumno();

        String nombres = jTextFieldNombre.getText();
        alumno.establecerNombre(nombres);
        
        String telefono = jTextFieldTelefono.getText();
        alumno.establecerTelefono(telefono);
        
        String direccion = jTextFieldDireccion.getText();
        alumno.establecerDireccion(direccion);

        String matricula = jTextFieldMatricula.getText();
        alumno.establecerMatricula(matricula);
        
        String Correo = jTextFieldCorreo.getText();
        alumno.establecerCorreo(Correo);
        
        String licenciatura = jComboBoxLicenciatura.getSelectedItem().toString();
        alumno.establecerLicenciatura(licenciatura);
        
        return alumno;
    }
    
    /**
     * @return Devuelve verdadero en caso de tener una licenciatura seleccionada
     */
    private boolean licenciaturaCorrecta(){
        return jComboBoxLicenciatura.getSelectedIndex() != 0;
    }
    
    /**
     * verifica que todos los campos esten sin errores
     * @return Devuelve verdadero cuando todos los campos son correctos
     */
    private boolean sonCamposCorrectos(){
    
        if(jTextFieldNombre.getToolTipText() == null
            && jTextFieldDireccion.getToolTipText() == null
            && jTextFieldTelefono.getToolTipText() == null
            && jTextFieldMatricula.getToolTipText() == null
            && licenciaturaCorrecta()    
            && jTextFieldCorreo.getToolTipText() == null) {
            datosCompletos = true;
            boolean sinErrores = true;
            return sinErrores;
            
        }else{
            datosCompletos = false;
        }
        
        boolean conErrores = false;
        return conErrores;
    }
    
    /**
     * solicita la confirmacion para la actualizacion del alumno
     */
    private void actualizarInformacion(){
        if(sonCamposCorrectos()){
            Alumno alumno = construirAlumno();
            GestorAlumnos administrador = new GestorAlumnos();
            administrador.actualizar(alumno);
            cerrar();
        }else{
            administradorMensajes.mensaje(INFO_ALUMNO_INCOMPLETA);
        }
    }
    
    /**
     * cierra la ventana
     */
    private void cerrar(){
        dispose();
    }
    
    /**
     * establece el fondo de color blanco
     */
    private void establecerFondoYPosicion(java.awt.Frame _pantallaPadre){
        //cambia el color dle jframe
        this.getContentPane().setBackground(Color.white);
        this.setLocationRelativeTo(_pantallaPadre);
    }
    
    /**
     * muestra los botones para la actualizacion de un alumno
     */
    private void mostrarBotonesActualizacion(){
        jPanelBotones.remove(jButtonAceptar);
        
        javax.swing.GroupLayout jPanelBotonesLayout = new javax.swing.GroupLayout(jPanelBotones);
        jPanelBotones.setLayout(jPanelBotonesLayout);
        jPanelBotonesLayout.setHorizontalGroup(
            jPanelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelMensaje)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButtonActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelBotonesLayout.setVerticalGroup(
            jPanelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCancelar)
                    .addComponent(jButtonActualizar)
                    .addComponent(jLabelMensaje))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }
    
    /**
     * muestra la informacion del alumno con la que se cuenta
     * @param _alumno 
     */
    private void mostrarInformacion(String _matricula){
        Alumno alumno = buscarAlumno(_matricula);
        
        String nombre = alumno.obtenerNombre();
        jTextFieldNombre.setText(nombre);
        
        String telefono = alumno.obtenerTelefono();
        jTextFieldTelefono.setText(telefono);
        
        String direccion = alumno.obtenerDireccion();
        jTextFieldDireccion.setText(direccion);
        
        String matricula = alumno.obtenerMatricula();
        jTextFieldMatricula.setText(matricula);
        
        String correo = alumno.obtenerCorreo();
        jTextFieldCorreo.setText(correo);
        
        String licenciatura = alumno.obtenerLicenciatura();
        ponerLicenciatura(licenciatura);
    }
    
    /**
     * establece la licenciatura del alumno
     * @param _licenciatura 
     */
    private void ponerLicenciatura(String _licenciatura){
        
        final int todasOpciones = 7;
        for(int contLic = 0; contLic < todasOpciones; contLic ++){
            String licenciatura = jComboBoxLicenciatura.getItemAt(contLic).toString();
           if(_licenciatura.equals(licenciatura)){
               jComboBoxLicenciatura.setSelectedIndex(contLic);
            }
        }
    }
    
    /**
     * inicia el proceso de registro solicitando el estado del formulario y
     * la confirmacion para registrar al nuevo usuario
     */
    private void registrarNuevoAlumno(){
        if(sonCamposCorrectos()){
            Alumno alumno = construirAlumno();
            GestorAlumnos administrador = new GestorAlumnos();
            administrador.agregar(alumno);
            cerrar();
        }else{
            administradorMensajes.mensaje(INFO_ALUMNO_INCOMPLETA);
        }
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAceptar;
    private javax.swing.JButton jButtonActualizar;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JComboBox jComboBoxLicenciatura;
    private javax.swing.JLabel jLabelCorreo;
    private javax.swing.JLabel jLabelDireccion;
    private javax.swing.JLabel jLabelLicenciatura;
    private javax.swing.JLabel jLabelMatricula;
    private javax.swing.JLabel jLabelMensaje;
    private javax.swing.JLabel jLabelNombres;
    private javax.swing.JLabel jLabelTelefono;
    private javax.swing.JPanel jPanelAlumno;
    private javax.swing.JPanel jPanelBotones;
    private javax.swing.JPanel jPanelFondo;
    private javax.swing.JPanel jPanelPersona;
    private javax.swing.JTextField jTextFieldCorreo;
    private javax.swing.JTextField jTextFieldDireccion;
    private javax.swing.JTextField jTextFieldMatricula;
    private javax.swing.JTextField jTextFieldNombre;
    private javax.swing.JTextField jTextFieldTelefono;
    // End of variables declaration//GEN-END:variables
    private boolean datosCompletos;
    private final GestorMensajes administradorMensajes;
    private final ControladorCamposTexto controladorCampos;
}